package 二叉树相关问题.中度题;

import java.util.ArrayList;
import java.util.List;

public class 所有可能的满二叉树 {

    public List<TreeNode> allPossibleFBT(int N) {
        List<TreeNode> list = new ArrayList<>();
        if (N%2==0)
            return list;
        if (N==1)
            list.add(new TreeNode(0));
        for (int i = 1; i < N; i++) {
            List<TreeNode> left = allPossibleFBT(i);
            List<TreeNode> right = allPossibleFBT(N - i - 1);
            for (TreeNode leftNode : left) {
                for (TreeNode rightNode : right) {
                    TreeNode root = new TreeNode(0);
                    root.left=leftNode;
                    root.right=rightNode;
                    list.add(root);
                }
            }
        }
        return list;
    }
}
